import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import tailwindcss from "@tailwindcss/vite";

// https://vite.dev/config/
export default defineConfig({
    plugins: [vue(), tailwindcss()],

    // 构建优化
    build: {
        // 启用代码分割
        rollupOptions: {
            output: {
                manualChunks: {
                    // 将Vue相关库分离
                    "vue-vendor": ["vue", "vue-router"],
                    // 将UI库分离
                    "ui-vendor": ["@headlessui/vue"],
                    // 将工具库分离
                    "utils-vendor": ["pinia"],
                },
            },
        },
        // 启用压缩
        minify: "terser",
        terserOptions: {
            compress: {
                drop_console: true,
                drop_debugger: true,
            },
        },
        // 设置chunk大小警告限制
        chunkSizeWarningLimit: 1000,
        // 启用CSS代码分割
        cssCodeSplit: true,
        // 启用资源内联阈值
        assetsInlineLimit: 4096,
    },

    // 开发服务器优化
    server: {
        // 启用预构建
        force: true,
    },

    // 依赖预构建优化
    optimizeDeps: {
        include: ["vue", "vue-router", "pinia", "@headlessui/vue"],
        exclude: [],
    },

    // 静态资源处理
    assetsInclude: [
        "**/*.svg",
        "**/*.png",
        "**/*.jpg",
        "**/*.jpeg",
        "**/*.gif",
        "**/*.webp",
    ],
});
